#include "configset.h"


ConfigWid::ConfigWid(QJsonObject json,QWidget *parent)
    : QDialog(parent)
    , _ui(new Ui::DialogModbus)
{
    _ui->setupUi(this);

    qDebug()<<"123";
    QString strcmd =  json.value("cmd").toString();
    if(strcmd.isEmpty())
        _ui->comboBox->setCurrentIndex(0);
    else
        _ui->comboBox->setCurrentText(json.value("cmd").toString());

    onDealCurrIndexChanged();
    connect(_ui->comboBox,     SIGNAL(currentIndexChanged(int)),this,SLOT(onDealCurrIndexChanged(int)));
}

QJsonObject  ConfigWid::getConfig(void)
{
    QJsonObject TmpJson ;
    TmpJson.insert("ret",1); //如果没有配置完成 就返回0  这样主界面就可以知道没有配置完成 这里可以先模拟成设置成功

    TmpJson.insert("cmd",_ui->comboBox->currentText());
    TmpJson.insert("detail",_ui->comboBox->currentText());
    return TmpJson;
}

void ConfigWid::onDealCurrIndexChanged(void)
{
    if(_ui->comboBox->currentText() == "返回string")
    {
      _ui->lineEdit->setValidator(0);
    }
    else if(_ui->comboBox->currentText() == "返回int")
    {
        QIntValidator *validator = new QIntValidator(-2147483648, 2147483647, this);
        _ui->lineEdit->setValidator(validator);
    }
    else if(_ui->comboBox->currentText() == "返回uint")
    {
        QIntValidator *validator = new QIntValidator(0, 4294967295, this);
        _ui->lineEdit->setValidator(validator);
    }
    else if(_ui->comboBox->currentText() == "返回float")
    {
        QIntValidator *validator = new QIntValidator(0, 4294967295, this);
        _ui->lineEdit->setValidator(validator);
    }
    else if(_ui->comboBox->currentText() == "返回Hex")
    {

    }
    else if(_ui->comboBox->currentText() == "返回Bool")
    {

    }
    else if(_ui->comboBox->currentText() == "返回测试失败")
    {
        _ui->lineEdit->setValidator(0);
    }
}
